//
//  HWNewdetailsDaoView.m
//  HWanGame
//
//  Created by 陈道斌 on 2021/9/7.
//  Copyright © 2021 Chendaobin. All rights reserved.
//

#import "HWNewdetailsDaoView.h"

#import "HWJietuCollectionViewCell.h"
#import "HWGameJiamJieCell.h" // 简介的Cell
#import "HWFuliTableViewCell.h" // 福利Cell
#import "HWYouxiLiBaoTableViewCell.h" //  游戏礼包
#import "HWXiHuanTableViewCell.h" //  游戏喜欢
#import "HWfulikongzhqiViewController.h"
#import "HWpinglunModel.h"
#import "HWpinglunHeaderView.h"
#import "HWpinglunfootView.h"
#import "HWpinglunFrame.h"
#import "HWpinglunxiangqingshituView.h"
#import "HWLoginController.h"
#import "JXPagerView.h"

#import "CLPlayerView.h"
#import "HWNewCommentsTableViewCell.h"


@interface HWNewdetailsDaoView()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UIScrollViewDelegate,HWpinglunHeaderViewdelegate,HWpinglunfootViewDelegate,JXPagerViewListViewDelegate>

@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);


@property(strong,nonatomic) NSDictionary *xiangqngDic; // 详情字典
@property(strong,nonatomic) UITableView *maintablview;
@property(strong,nonatomic) UIView *hederView;
@property(strong,nonatomic) UICollectionView *maincollectionView;
@property(strong,nonatomic) NSArray *sectinArr;
@property(strong,nonatomic) UIScrollView *scrollView; //
@property(strong,nonatomic) NSMutableDictionary  *dataDic;
@property(strong,nonatomic) NSString *dataStr;
@property(assign,nonatomic) bool zhangkan;
@property(strong,nonatomic) NSMutableArray *imgsMuArr;
@property(strong,nonatomic) NSMutableArray *dataMuArr;
@property(strong,nonatomic) NSString *video_url; // 存储视屏Url

/**CLplayer*/
@property (nonatomic, weak) CLPlayerView *playerView;
@property(assign,nonatomic) BOOL isbofan;

@end



@implementation HWNewdetailsDaoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStylePlain];
//        self.tableView.backgroundColor = [UIColor whiteColor];
//        self.tableView.tableFooterView = [UIView new];
//        self.tableView.dataSource = self;
//        self.tableView.delegate = self;
//        // [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
//        [self addSubview:self.tableView];
        self.video_url = @"";
        self.sectinArr = @[@"游戏简介",@"游戏福利",@"玩家评论",@"猜你喜欢"];
        [self setUI];
        [self addHederView];
       //  [self xiangqingmiaoshu];
        [self listeningNSNotificationCenter];
        
        
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];

    self.maintablview.frame = self.bounds;
}


- (void)refreshData {
    
    [self xiangqingmiaoshu];
    
}


- (void)guanbibofan {
    
    [_playerView destroyPlayer];
    
}





//#pragma  mark ------- 监听通知
- (void)listeningNSNotificationCenter {

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshTableView:) name:@"xianqingtongzhSentimentOnTheSlide" object:nil];
    
    
}

- (void)refreshTableView:(NSNotification *)noti {

    NSLog(@"%@",noti.userInfo);
    NSDictionary *dic = noti.userInfo;
    NSString *str  = [NSString stringWithFormat:@"%@",dic[@"rolling"]];
    int  a = [str intValue];
    // judgeStr
    if (a == 1) {

        self.zhangkan = YES;
        [self.maintablview reloadData];



    } else {

        self.zhangkan = NO;
         [self.maintablview reloadData];
    }


}








// 详情的接口
- (void)xiangqingmiaoshu {
    
    
    NSDictionary *parametes  = nil;
    if ([[HWLocallyStoredData getLoginUserID] isEqualToString:@""]) {
        parametes = @{
                                @"id" : self.gameId,
                                @"ios" : @"1",
                                @"ct" :  @"app2021",
                                @"ac" : @"gameinfo_content"
                                                  };
        
        
    } else {
        
        
              parametes = @{
                                    @"id" : self.gameId,
                                    @"ios" : @"1",
                                    @"uid" : [HWLocallyStoredData getLoginUserID],
                                    @"ct" : @"app2021",
                                    @"ac" : @"gameinfo_content"
                                            };
        
        
    }
       
      
    
   
    
      
    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
          
         
          
          NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
          
          if ([codeStr intValue] == 1) {
              NSLog(@"%@",response);
              self.xiangqngDic = response;
           //    [self.mainaTableVie reloadData];
              
               self.dataDic =  [self.xiangqngDic mutableCopy];
               self.dataStr = self.xiangqngDic[@"content"];
               self.zhangkan = NO;
               NSString *vidourl = [NSString stringWithFormat:@"%@",self.dataDic[@"imgs"][@"video"][@"video_url"]];
               NSString *video_pic = [NSString stringWithFormat:@"%@" ,self.dataDic[@"imgs"][@"video"][@"video_pic"]];
              self.imgsMuArr  = [[NSMutableArray alloc]init];
              
           
              if ([self.dataDic[@"imgs"][@"imgs"] isKindOfClass:[NSArray class]] ) {
                  self.imgsMuArr =   [self.dataDic[@"imgs"][@"imgs"] mutableCopy];
              }
              
              
           ///   self.imgsMuArr =   [self.dataDic[@"imgs"][@"imgs"] mutableCopy];
              
              
             //  self.imgsMuArr =   [self.dataDic[@"imgs"][@"imgs"] mutableCopy];
              
              if ([vidourl isEqualToString:@""]) {
                   
              } else {
                  
                  self.video_url = vidourl;
                  
                  [self.imgsMuArr insertObject:video_pic atIndex:0];
                  
                  
              }
              
               [self detailsInterfaceCommentsxiangqing];
               [self.maincollectionView reloadData];
               [self.maintablview reloadData];
              
        
          } else {
              
              
              [MBProgressHUD showError:response[@"message"]];
              
          }
       
          
          
      } failure:^(NSString *error) {
        
          
      }];
    
    
    
}


// 详情评论界面
- (void)detailsInterfaceCommentsxiangqing {
    
    // 斗
    
    NSDictionary   *parametes = @{
                                              @"id" : self.gameId,
                                              @"ios" : @"1",
                                              @"ct" :  @"app2021",
                                              @"ac" : @"gameinfo_pllist"
                                              };
    
    
    if ([[HWLocallyStoredData getLoginUserID] isEqualToString:@""]) {
    
            parametes = @{
                                                  @"id" : self.gameId,
                                                  @"ios" : @"1",
                                                  @"ct" :  @"app2021",
                                                  @"ac" : @"gameinfo_pllist"
                                                  };
        
    } else {
        
           parametes = @{
                                              @"id" : self.gameId,
                                              @"ios" : @"1",
                                              @"ct" :  @"app2021",
                                              @"uid": [HWLocallyStoredData getLoginUserID],
                                              @"ac" : @"gameinfo_pllist"
                                              };
    
        
        
    }
    
    
    
    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
          
         
          
          NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
          
          if ([codeStr intValue] == 1) {
                NSLog(@"%@",response);

              
              self.dataMuArr = [[NSMutableArray alloc] init];
               
              NSMutableArray *arr  =  [HWpinglunModel mj_objectArrayWithKeyValuesArray: response[@"data"]];
              
              for (int i = 0; i < arr.count; i++) {
                  
                  HWpinglunFrame *mode =  [[HWpinglunFrame alloc]init];
                  mode.datamodel = arr[i];
                  [self.dataMuArr addObject: mode];
                
              }
              
               [self.maincollectionView reloadData];
               [self.maintablview reloadData];
              
        
          } else {
              
              
             //   [MBProgressHUD showError:response[@"message"]];
              
          }
       
          
          
      } failure:^(NSString *error) {
        
          
      }];
    
    
    
    
    
    
    
}









- (void)setUI {

   // self.maintablview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW,  1000) style:UITableViewStylePlain];
    self.maintablview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,self.frame.size.width, self.frame.size.height) style:UITableViewStylePlain];
    self.maintablview.delegate = self;
    self.maintablview.dataSource = self;
    self.maintablview.tag = 10;
    self.maintablview.scrollEnabled = YES;
    self.maintablview.separatorStyle =  UITableViewCellSeparatorStyleNone;
    self.maintablview.tableFooterView = [[UIView alloc]init];
    self.maintablview.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.maintablview];
    
    
}

//- (void)setDataStr:(NSString *)dataStr {
//
//
//    _dataStr = dataStr;
//
//    self.sectinArr = @[@"游戏简介",@"福利",@"游戏礼包",@"猜你喜欢"];
//
//    [self.maincollectionView reloadData];
//
//    [self.maintablview reloadData];
//
//}


// 设置HederView
- (void)addHederView {
    
    self.hederView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 180*CFLScaleValue+10)];
  //   self.hederView.backgroundColor = [UIColor redColor];
    self.maintablview.tableHeaderView = self.hederView;
    
    UILabel   *youxiJietuLabel = [[UILabel alloc]initWithFrame:CGRectMake(16,  0, 300, 15)];
    youxiJietuLabel.text = @"游戏截图";
    youxiJietuLabel.text = @"";
    youxiJietuLabel.textColor = RGB(51, 51, 51);
    youxiJietuLabel.textAlignment  = NSTextAlignmentLeft;
    youxiJietuLabel.font = [UIFont systemFontOfSize:13];
  //  youxiJietuLabel.backgroundColor = [UIColor yellowColor];
    [self.hederView addSubview:youxiJietuLabel];
    // 添加截图
    [self screenshotsView];
}
 // 添加截图
- (void)screenshotsView   {
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 8*CFLScaleValue;
 //   layout.minimumInteritemSpacing = 30;
    
    self.maincollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(9, 10, kScreenW-9,180*CFLScaleValue) collectionViewLayout:layout];
    self.maincollectionView.showsHorizontalScrollIndicator = NO;
    self.maincollectionView.delegate = self;
    self.maincollectionView.dataSource = self;
   // self.maincollectionView.backgroundColor = RGB(217, 247, 250);
    self.maincollectionView.backgroundColor = [UIColor whiteColor];
    
    //self.maincollectionView.alwaysBounceHorizontal = YES;
    
    
  //  self.maincollectionView.contentInset = UIEdgeInsetsMake(6, 10, 6, 10);
    // [self.maincollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];  //  一定要设置
   [self.maincollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellID1"];
    [self.maincollectionView  registerNib:[UINib nibWithNibName:@"HWJietuCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"cellID"];
    //  [UINib nibWithNibName:@"HWShouYouCollectionViewCell" bundle:nil]
    
    self.maincollectionView.userInteractionEnabled = YES;
    [self.hederView  addSubview:self.maincollectionView];
    
    
    UIView  *fengexianView = [[UIView alloc]initWithFrame:CGRectMake(18,180*CFLScaleValue+36+10-1, kScreenW-36, 1)];
    fengexianView.backgroundColor =RGB(237, 237, 237);
    fengexianView.hidden = YES;
    [self.hederView addSubview:fengexianView];
    
    

    
}


#pragma mark ------ UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return  self.sectinArr.count;
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 2) {
        
        if ( self.dataMuArr.count > 0 ) {
            
            HWpinglunFrame *frame =     self.dataMuArr[0];
            NSUInteger cout =    [frame.datamodel.son_list count];
            if (cout > 4) {
                
                return  4;
                
            }
            return     [frame.datamodel.son_list count];
            
        } else {
            
            return  0;
            
        }
        
    
        
        
    }
    
    return  1;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0 ) {
        
        
        static NSString   *cellID = @"cellId";
        HWGameJiamJieCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        
        if (!cell ) {
            cell = [[HWGameJiamJieCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        cell.selectionStyle  = UITableViewCellSelectionStyleNone;
        cell.zhangkan = self.zhangkan;
        cell.dataStr = self.dataStr;
        cell.backgroundColor = [UIColor whiteColor];
        return  cell;
        

    } else if (indexPath.section == 1){
        
        static NSString *cellID = @"fulieCell";
    
        HWFuliTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            
            cell = [[HWFuliTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        cell.selectionStyle  = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        cell.fuli_infoSt = self.dataDic[@"fuli"];
        return  cell;
    
        
    } else if (indexPath.section == 2) {
        
        static NSString *cellID = @"pinglunceliD";
        HWNewCommentsTableViewCell *cell =  [tableView dequeueReusableCellWithIdentifier:cellID];
        
       
        if (cell == nil ) {
           cell =  [[HWNewCommentsTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
            
        }

        HWpinglunFrame *frame =     self.dataMuArr[0];
        HWpinglunModel *model =      frame.datamodel.son_list[indexPath.row];
        cell.frameModel = frame;
        cell.model = model ;
       //  cell.backgroundColor = [UIColor redColor];
       
        cell.selectionStyle =UITableViewCellSelectionStyleNone;
        
       if (indexPath.row == 3) {
           
           cell.chakanLabel.hidden = NO;
           cell.neirongtextview.hidden = YES;
           
           
       } else {
           cell.chakanLabel.hidden = YES;
           cell.neirongtextview.hidden = NO ;
           
       }
       
        return  cell;
        
        
        
        
        
    }else if (indexPath.section == 3) {
        
        
        static NSString *cellID = @"xihuanID";
        
        HWXiHuanTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        
        if (!cell) {
            
            cell =  [[HWXiHuanTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        
        }
        
        cell.gameArr = self.dataDic[@"cnlike"];
        cell.selectionStyle =  UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
    
        return  cell;
        

    }else  {
        
        
        static NSString *cellID = @"celiD";
        UITableViewCell *cell =  [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.backgroundColor = [UIColor whiteColor];
        return  cell;
        
        
    }
    
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
  //    NSLog(@"dijioioijohiohio");
    
    if (indexPath.section == 1) {
        
         NSLog(@"dijioioijohiohio");
         
        if ([self.dataDic[@"fuli_info"] isEqualToString:@""]) {
             //   self.namelabee.text = @"暂无福利活动,敬请期待！";
        } else {
            HWfulikongzhqiViewController * fuli = [[HWfulikongzhqiViewController alloc] init];
            fuli.neironStr =  [NSString stringWithFormat:@"%@",self.dataDic[@"fuli"]];
             [[HWViewUtils getCurrentVC].navigationController  pushViewController:fuli animated:YES];
                         
              
        }
          
        
       
        
        
    }
    
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
      NSString *str = self.dataStr;
    
      CGFloat  contentH = [self calculateRowHeight:str fontSize:12];
        
      if (self.zhangkan == NO) {
          
          if (contentH > 44) {
            
              return  44+12+10+3;
              
          } else {
              
             // return  contentH+12+10+3;
              return  contentH+3;
              
          }
            
      
      } else {
            
          
          return contentH+12+10+3;
          
      }
    
        
    
       
    }else if (indexPath.section == 1) {
        
        return  75*CFLScaleValue+6;
        
        
    } else if (indexPath.section == 2) {
        
        
        
        if (indexPath.row == 3) {
            return  20;
        }
        
        HWpinglunFrame *frame =     self.dataMuArr[0];
        HWpinglunModel *model =      frame.datamodel.son_list[indexPath.row];
        
        
         NSString  *content = [NSString stringWithFormat:@"%@:%@",model.user_name, model.content];
        
        
        
        if (model.beihuifu_user_name == nil  ) {
            
            content = [NSString stringWithFormat:@"%@:%@",model.user_name, model.content];
            
             
        } else {
            
            content = [NSString stringWithFormat:@"%@回复%@:%@",model.user_name,model.beihuifu_user_name ,model.content];
            
        }
       
      //   content = @"四川成家长把孩子送进校园后，纷纷贴墙“暗中观察”。9月1日，全国多地迎来都一小学开学，家长把孩子送进校后，纷纷贴墙“暗中";
        
        CGSize   size2 =    [WMUtil sizeWithFont1:[UIFont systemFontOfSize:14] maxSize:CGSizeMake(kScreenW-60-15-20, 2000) string:content];
        CGFloat a=  8;
      //   self.neirongtextview.text = content;
        if (size2.height < 17) {
            return   size2.height+a ;
            
        } else {
            // a=  -10;
            return   size2.height+a;
            
        }
        
        
        
        return 10 ;
        
    }else if (indexPath.section == 3) {
        
        
       return  58*CFLScaleValue+21+6;
        
    }else {
        
        return 100;
    }
   
    
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if(section == 2) {
    
        
        if (self.dataMuArr.count > 0 ) {
            HWpinglunFrame *frame =     self.dataMuArr[0];
            return   frame.sectionHeight;
        }
        
        return  40;
         

    }
    
    return  36;
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    if (section == 2) {
        if (self.dataMuArr.count > 0 ) {
            return  36;
        } else {
            
            return  0.01;
        }
        
         
        
    }
    
    return  0.01;
    
    
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    
    if (section == 2  ) {
        
        if (self.dataMuArr.count > 0 ) {
            
            HWpinglunHeaderView *view = [HWpinglunHeaderView headFooterViewWithTableview:tableView];
            // view.frame = CGRectMake(0, 0, kScreenW, 100);
            view.model = self.dataMuArr[0];
            view.delegate = self;
            
            view.backgroundColor = [UIColor redColor];
        
            return view;
            
            
        }else {
            
            
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 40)];
            label.backgroundColor = RGB(255, 255, 255);
            label.layer.cornerRadius = 32;
            label.layer.masksToBounds = YES;
            //label.backgroundColor = [UIColor redColor];

            label.textColor = RGB(136, 136 , 136);
            label.textAlignment = NSTextAlignmentCenter;
            label.font = [UIFont systemFontOfSize:14];
            label.text = @"暂无评论";
            
            
            
            return  label;
            
            
            

        }
       
        
        
          
    } else {
        UIView *sectinView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 36)];
        UILabel *textlabel = [[UILabel alloc]initWithFrame:CGRectMake(16, 0, 200, 36)];
        textlabel.text = self.sectinArr[section];
       //  textlabel.backgroundColor = [UIColor redColor];
        textlabel.textColor = RGB(51, 51, 51);
        
        textlabel.font = [UIFont systemFontOfSize:13];
        [sectinView addSubview:textlabel];
        
        return sectinView;
        
        
    }
    
//    UIView *sectinView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 36)];
//    UILabel *textlabel = [[UILabel alloc]initWithFrame:CGRectMake(16, 0, 200, 36)];
//    textlabel.text = self.sectinArr[section];
//   //  textlabel.backgroundColor = [UIColor redColor];
//    textlabel.textColor = RGB(51, 51, 51);
//
//    textlabel.font = [UIFont systemFontOfSize:13];
//    [sectinView addSubview:textlabel];
//
    
    
    
    
    
    
    
    
    
    
   
  
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    if (section == 2) {
        
        if (self.dataMuArr.count > 0 ) {
            
            
            HWpinglunfootView *view = [HWpinglunfootView headFooterViewWithTableview:tableView];
            // view.frame = CGRectMake(0, 0, kScreenW, 100);
            view.model = self.dataMuArr[0];
            view.delegate = self;
            view.backgroundColor = [UIColor redColor];
            return  view;
            
        }else {
            
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 0.01)];
            return  view;
        
        }
        
    
    }else {
        
        
        UIView *view = [[UIView alloc]init];
        return  view;
        
        
        
        
    }
    
    
    
}





- (void)HWpinglunHeaderView:(HWpinglunFrame*)frame {
    
    
    HWpinglunxiangqingshituView *pilunxiang = [[HWpinglunxiangqingshituView alloc] init];
    pilunxiang.pid = frame.datamodel.id;
    pilunxiang.gidStr = frame.datamodel.gid;
    pilunxiang.idStr = frame.datamodel.id;
   // [self.navigationController pushViewController:pilunxiang animated:YES];
    
    [[HWViewUtils getCurrentVC].navigationController pushViewController:pilunxiang animated:YES];
    
    
    
}


- (void)HWpinglunfootView:(HWpinglunFrame *)modeFrame sectionInt:(NSInteger)section {
    
    
    
    if ([[HWLocallyStoredData getLoginUserID] isEqualToString:@""]) {
        
        HWLoginController *login = [[HWLoginController alloc]init];
        [[HWViewUtils getCurrentVC].navigationController  pushViewController:login animated:YES];
     
        
        return ;
        
    }
    
    NSString *userID = [HWLocallyStoredData getLoginUserID];
    int t = [WMUtil getRandomNumber:101 to:998];
    NSString *tStr = [NSString stringWithFormat:@"%ld%d",[WMUtil getTimeSp],t];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
    NSString *signMD5 = [WMUtil md5HexDigest:sign];

    NSDictionary *parametes = @{
                                @"ct" : @"app2021",
                                @"ac" : @"pinglun_zan",
                                @"ios" : @"1",
                                @"uid" :userID,
                                @"t" :tStr,
                                @"sign":signMD5,
                                @"id":modeFrame.datamodel.id
                                };
    
    
     //  @"images" :ico,
    
    [MBProgressHUD showMessage:@"正在点赞..."];
    [HWWebUtils doPostWithParameters:parametes progress:nil success:^(id response) {
        
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
           [MBProgressHUD hideHUD];
             
             
             if ([codeStr intValue] == 1) {
                 // [self.navigationController popViewControllerAnimated:YES];
               //    [MBProgressHUD  showError:@"发表评论成功"];
                 [self detailsInterfaceCommentsxiangqing];
                 

             } else {
                 
                  [MBProgressHUD  showError:response[@"message"]];
                 
             }
             NSLog(@"%@",response);
        
    } failure:^(NSString *error) {
         [MBProgressHUD  showError:@"加载失败"];
 
    }];
    
    
}



- (void)HWpinglunfootView:(HWpinglunFrame *)modeFrame {
    
    
    HWpinglunxiangqingshituView *pilunxiang = [[HWpinglunxiangqingshituView alloc] init];
    pilunxiang.pid = modeFrame.datamodel.id;
    pilunxiang.gidStr = modeFrame.datamodel.gid;
    pilunxiang.idStr = modeFrame.datamodel.id;
    [[HWViewUtils getCurrentVC].navigationController  pushViewController:pilunxiang animated:YES];
    
    
    
    
    
}





#pragma mark  ------------  计算文字的高度


- (CGFloat)calculateRowHeight:(NSString *)string fontSize:(NSInteger)fontSize

{
    
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]};
    
    
    
    CGRect rect = [string boundingRectWithSize:CGSizeMake(kScreenW-36, MAXFLOAT)/*计算高度要先指定宽度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                   
                   NSStringDrawingUsesFontLeading attributes:dic context:nil];
    
    return rect.size.height;
    
}






#pragma mark  ------------- UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return [self.imgsMuArr count];
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([self.video_url isEqualToString:@""]) {
       
        
        HWJietuCollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellID" forIndexPath:indexPath];
        NSString *icoStr =self.imgsMuArr[indexPath.row];
        NSURL *url = [NSURL URLWithString:icoStr];
        [cell.jietuIcoimasgeView sd_setImageWithURL:url];
        return cell;
        
         
    } else {
        
        
        if (indexPath.row == 0 ) {
          //   UICollectionViewCell
            
            
            UICollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellID1" forIndexPath:indexPath];
//            NSString *icoStr =self.imgsMuArr[indexPath.row];
//            NSURL *url = [NSURL URLWithString:icoStr];
//            [cell.jietuIcoimasgeView sd_setImageWithURL:url];
            
            UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 340, 180)];
            //imageview.backgroundColor = [UIColor redColor];
            NSString *icoStr =self.imgsMuArr[indexPath.row];
            NSURL *url = [NSURL URLWithString:icoStr];
            imageview.contentMode  = UIViewContentModeScaleAspectFill;
            [imageview sd_setImageWithURL:url];
            [cell.contentView addSubview:imageview];
            
            UIButton     *_button = [UIButton buttonWithType:UIButtonTypeCustom];
            _button.frame = CGRectMake((340-60)/2, (180-60)/2, 60, 60);
          //   [_button setBackgroundImage:[self getPictureWithName:@"CLPlayBtn"] forState:UIControlStateNormal];
             [_button setBackgroundImage:[UIImage imageNamed:@"btn_video"] forState:UIControlStateNormal];
           
            _button.userInteractionEnabled = NO;
            
            [cell.contentView addSubview:_button];
            
          
           // _button.backgroundColor = [UIColor redColor];
         
            
            
            
            
            return cell;
            
        } else {
            
            HWJietuCollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellID" forIndexPath:indexPath];
            NSString *icoStr =self.imgsMuArr[indexPath.row];
            NSURL *url = [NSURL URLWithString:icoStr];
            [cell.jietuIcoimasgeView sd_setImageWithURL:url];
            return cell;
            
            
            
        }
      
        
        
    }
    
    
//    HWJietuCollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellID" forIndexPath:indexPath];
//    NSString *icoStr =self.imgsMuArr[indexPath.row];
//    NSURL *url = [NSURL URLWithString:icoStr];
//    [cell.jietuIcoimasgeView sd_setImageWithURL:url];
//    return cell;
//
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if ([self.video_url isEqualToString:@""]) {
        
        return  CGSizeMake(110*CFLScaleValue,180*CFLScaleValue);
        
    } else {
        
        if (indexPath.row == 0 ) {
            
            return  CGSizeMake(340,180);
             
        }
        
    }

    return CGSizeMake(110*CFLScaleValue,180*CFLScaleValue);
}



//- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
//
//    DLog(@"点击精品手游单元格");
//}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    DLog(@"点击精品手游单元格11111");
    
    if([self.video_url isEqualToString:@""]) {
        
        
        
    } else {
        
        if (indexPath.row == 0 ) {
            [self bofangshiping:indexPath];
            
            return;
             
        } else {
            
            
            
        }
        
        
    }
    
    UIScrollView *bgView = [[UIScrollView alloc] init];
    bgView.frame = [UIScreen mainScreen].bounds;
    bgView.backgroundColor = [UIColor blackColor];
    UITapGestureRecognizer *tapBg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgView:)];
    [bgView addGestureRecognizer:tapBg];
    bgView.pagingEnabled = YES;
    self.scrollView = bgView;
    [[[UIApplication sharedApplication] keyWindow] addSubview:bgView];
    
    self.scrollView.delegate = self;
    NSArray *imagesarr =  self.imgsMuArr;
    [self.scrollView setContentSize:CGSizeMake( imagesarr.count*SCREEN_WIDTH, SCREEN_HEIGHT)];
    
      self.scrollView.contentOffset = CGPointMake(indexPath.row * SCREEN_WIDTH, 0);
    
    
       for (int i = 0 ; i <  imagesarr.count; i ++) {
           
//           NSLog(@"youzhima%lu", (unsigned long)self.entity.imgs.count);
          


           UIImageView *imageView = [[UIImageView alloc] init];
           // imageView.image =  [UIImage imageNamed:self.entity.imgs[i]];
           
           // [imageView sd_setImageWithURL:[NSURL URLWithString:self.entity.imgs[i]] placeholderImage:[UIImage imageNamed:@""]];
           // imageView.image = [UIImage imageNamed:@"1"];
           
           imageView.tag = i+100;
           
           // imageView.frame = [bgView convertRect:picView.frame fromView:self.view];
           [bgView addSubview:imageView];
           
           //        CGRect frame = imageView.frame;
           //        frame.size.width = bgView.frame.size.width;
           //        frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width);
           //        frame.origin.x = i *  bgView.frame.size.width;
           //        frame.origin.y = (bgView.frame.size.height - frame.size.height) * 0.5;
           //        imageView.frame = frame;
           
           
           if (i == indexPath.row) {
          
               
                [imageView  sd_setImageWithURL:[NSURL URLWithString:imagesarr[i]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {

                       CGRect frame = imageView.frame;
                       frame.size.width = self.scrollView.frame.size.width;
                       frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width);
                       frame.origin.x = i *  self.scrollView.frame.size.width;
                       frame.origin.y = (self.scrollView.frame.size.height - frame.size.height) * 0.5;
                       imageView.frame = frame;
                       imageView.image = image;

               //        self.lastImageView =  imagView;
               //
               //        self.originalFrame = imagView.frame;


                   }];


               continue;
           }
           
           
           
       }
    
    
    
    
}


- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
    NSInteger leftI = scrollView.contentOffset.x / SCREEN_WIDTH;
    UIImageView *imagView = [self.scrollView viewWithTag:leftI+100];
    //  [imagView sd_setImageWithURL:[NSURL URLWithString:self.entity.imgs[i]] placeholderImage:[UIImage imageNamed:@""]];
    NSArray *imagesarr =   self.imgsMuArr;
    [imagView  sd_setImageWithURL:[NSURL URLWithString:imagesarr[leftI]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        
        CGRect frame = imagView.frame;
        frame.size.width = self.scrollView.frame.size.width;
        frame.size.height = frame.size.width * (imagView.image.size.height / imagView.image.size.width);
        frame.origin.x = leftI *  self.scrollView.frame.size.width;
        frame.origin.y = (self.scrollView.frame.size.height - frame.size.height) * 0.5;
        imagView.frame = frame;
        imagView.image = image;
        
//        self.lastImageView =  imagView;
//
//        self.originalFrame = imagView.frame;
        
        
    }];
    
    
    
    
    
    
    
    
    
    
    
    
}










-(void)tapBgView:(UITapGestureRecognizer *)tapBgRecognizer
{
    //    self.scrollView.contentOffset = CGPointZero;
    //    [UIView animateWithDuration:0.5 animations:^{
    //        self.lastImageView.frame = self.originalFrame;
    //        tapBgRecognizer.view.backgroundColor = [UIColor clearColor];
    //    } completion:^(BOOL finished) {
    //        [tapBgRecognizer.view removeFromSuperview];
    //        self.scrollView = nil;
    //        self.lastImageView = nil;
    //    }];
    
    self.scrollView.contentOffset = CGPointZero;
    [self.scrollView removeFromSuperview];
 
}





- (void)bofangshiping:(NSIndexPath *)index {
    
    UICollectionViewCell *cell =  [self.maincollectionView cellForItemAtIndexPath:index];
    
     
    
    [_playerView destroyPlayer];
    CLPlayerView *playerView = [[CLPlayerView alloc] initWithFrame:CGRectMake(0, -10, 340, 200)];
    _playerView = playerView;
    playerView.backgroundColor = [UIColor blackColor];
    [cell.contentView addSubview:_playerView];
    //视频地址
    _playerView.url = [NSURL URLWithString:self.video_url];

    [_playerView updateWithConfigure:^(CLPlayerViewConfigure *configure) {
        configure.topToolBarHiddenType = TopToolBarHiddenSmall;
        configure.autoRotate = NO;
        
//        config.smallGestureControl = YES;
    }];
    //播放
    [_playerView playVideo];
    //返回按钮点击事件回调
    [_playerView backButton:^(UIButton *button) {
        NSLog(@"返回按钮被点击");
    }];
    //播放完成回调
    [_playerView endPlay:^{
        //销毁播放器
        [self->_playerView destroyPlayer];
        self->_playerView = nil;
       //  self->_cell = nil;
       
        NSLog(@"播放完成");
    }];
    
    self.isbofan = YES;
    
    
    
    
}









/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/





- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    self.scrollCallback(scrollView);
}


#pragma mark - JXPagingViewListViewDelegate

- (UIScrollView *)listScrollView {
    return self.maintablview;
}

- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
    self.scrollCallback = callback;
}

- (UIView *)listView {
    return self;
}


@end
